﻿using System.Windows.Forms;
using System;
using System.Collections.Generic;
using ClassMedataBrowser.Domain;
namespace ClassMetadataBrowser.ToolControls
{
	public partial class ConfigurationWindow : Form
	{
		public event EventHandler ApplyConfiguration;
		private DataGridColumnsManager _manager;

		public ConfigurationWindow()
		{
			InitializeComponent();
		}

		public void AcceptColumnsManager(DataGridColumnsManager manager)
		{
			_manager = manager;
			PopulateColumns(manager, manager.Descriptor);
		}

		private void PopulateColumns(DataGridColumnsManager manager, ColumnsDescriptor columnsDescriptor)
		{
			foreach (KeyValuePair<string, string> pair in manager.GetColumns())
			{
				_gridViewColumns.Rows.Add(manager.IsVisible(pair.Key), pair.Value, pair.Key);
			}
			ShowColumnDescription(0);
		}

		private void BtnApplyClick(object sender, EventArgs e)
		{
			if (ApplyConfiguration != null)
				ApplyConfiguration(sender, e);
		}

		private void BtnAlternatingRowColorClick(object sender, EventArgs e)
		{

		}

		private void BtnRowColorClick(object sender, EventArgs e)
		{

		}

		private void BtnChangeFontClick(object sender, EventArgs e)
		{

		}

		private void GridViewCellClicked(object sender, DataGridViewCellEventArgs e)
		{
			ShowColumnDescription(e.RowIndex);
		}

		private void ShowColumnDescription(int rowIndex)
		{
			string columnName = _gridViewColumns.Rows[rowIndex].Cells[2].Value.ToString();
			_txtColumnDescription.Text = _manager.GetDescription(columnName);
		}
	}
}
